﻿using DataModelLibrary.Models;
using log4net.Repository.Hierarchy;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataModelLibrary.Services.Impl
{
    public class UserServiceImpl : UserService
    {
        private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private static UserServiceImpl userServiceImpl;
        public static UserServiceImpl Instance
        {
            get
            {
                if (userServiceImpl == null)
                    userServiceImpl = new UserServiceImpl();
                return userServiceImpl;
            }
        }
        private UserServiceImpl() { }
        public List<User> SelectAll()
        {
            SqlSugarClient db = SqlSugarClientHelper.Instance.ConnectDb();
            List<User> users = db.Queryable<User>().ToList();
            return users;
        }
        public User SelectOneByName(string username)
        {
            Logger.Info("开始查询");
            SqlSugarClient db = SqlSugarClientHelper.Instance.ConnectDb();
            User user = db.Queryable<User>().Where(s => s.userName == username).First();
            Logger.Info("结束查询");
            return user;
        }
    }
}
